﻿package temp 
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	
	/**
	 * 
	 * @author fly
	 */
	public class StopMC 
	{
		
		//立刻停止
		static public function StopDisplayList(container:DisplayObjectContainer):void {
			var child:DisplayObject;
			if (container is MovieClip)
				(container as MovieClip).stop();
			container.mouseEnabled = false;
			for (var i:Number = container.numChildren - 1; i >= 0; i--) {
				child = container.getChildAt(i);
				
				if (child is DisplayObjectContainer) {
					// 递归调用
					StopDisplayList(DisplayObjectContainer(child));
				}
				
				if(child is MovieClip)
				{
					(child as MovieClip).stop();
				}
				if (child is InteractiveObject)
				{
					(child as InteractiveObject).mouseEnabled = false;
				}
			}
		}
		
		//从第一帧开始播放
		static public function playDisplayList(container:DisplayObjectContainer):void {
			if (container == null) return;
			var child:DisplayObject;
			if (container is MovieClip)
				(container as MovieClip).play();
			container.mouseEnabled = false;
			for (var i:Number = container.numChildren - 1; i >= 0; i--) {
				child = container.getChildAt(i);
				
				if (child is DisplayObjectContainer) {
					// 递归调用
					playDisplayList(DisplayObjectContainer(child));
				}
				
				if(child is MovieClip)
				{
					(child as MovieClip).gotoAndPlay(1);
				}
				if (child is InteractiveObject)
				{
					(child as InteractiveObject).mouseEnabled = false;
				}
			}
		}
		
		//停在最后一帧
		static public function goAndStopDisplayListOnTheEnd(container:DisplayObjectContainer,total:int):void {
			var child:DisplayObject;
			if (container is MovieClip)
				(container as MovieClip).stop();
			container.mouseEnabled = false;
			for (var i:Number = container.numChildren - 1; i >= 0; i--) {
				child = container.getChildAt(i);
				
				if (child is DisplayObjectContainer) {
					// 递归调用
					goAndStopDisplayListOnTheEnd(DisplayObjectContainer(child),(child as MovieClip).totalFrames);
				}
				
				if(child is MovieClip)
				{
					(child as MovieClip).gotoAndStop(total);
				}
				if (child is InteractiveObject)
				{
					(child as InteractiveObject).mouseEnabled = false;
				}
			}
		}
	}
}